<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../css/iconfont.css" />
		<script src="../../js/jquery-1.11.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/mui.min.js"></script>
	</head>

	<body>
		<header class="mui-bar" style="background-color:#000000;" id="head1">
			<a class=" mui-icon mui-icon-left-nav mui-pull-left" id="back" style="color: #FFFFFF;">
				<font size="3">返回</font>
			</a>
			<h1 class="mui-title" style="color: #FFFFFF;">扫描二维码</h1>
		</header>
		<div id="code" style="position:relative;top:44px;width:100%;height:100%; background:#000000;">
			<!--盛放扫描控件的div-->
		</div>
		<!--<div class="mui-bar mui-bar-tab" style="background-color: #000000;">
			<a class="mui-tab-item mui-active" data-index="0">
				<span class="mui-icon iconfont icon-saoyisao"></span>
				<span class="mui-tab-label">扫码</span>
			</a>
			<a class="mui-tab-item mui-action-back" data-index="1">
				<span class="mui-icon iconfont icon-quxiao"></span>
				<span class="mui-tab-label">取消</span>
			</a>
		</div>-->
		<script type="text/javascript">
			var height = window.innerHeight - 44 + 'px'; //获取页面实际高度
			var width = window.innerWidth + 'px';
			document.getElementById("code").style.height = height;
			document.getElementById("code").style.width = width;

			var scan = null; //扫描对象  
			mui.plusReady(function() {
				mui.init();
				startRecognize();
			});
			
			function getQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
				var r = (window.location.hash || window.location.search).substr(1).match(reg);
				if (r != null) return unescape(r[2]); return null;
			}

			function startRecognize() {
				try {
					var filters;
					//自定义的扫描控件样式  
					var styles = {
						frameColor: "#0000FF",
						scanbarColor: "#0000FF"
					};
					//扫描控件构造  
					scan = new plus.barcode.Barcode('code', filters, styles);
					scan.onmarked = onmarked;
					scan.onerror = onerror;
					scan.start();
				} catch(e) {
					mui.alert("出现错误啦:\n" + e);
				}
			};

			function onerror(e) {
				miu.alert(e);
			};

			function onmarked(type, result) {
				var text = '';
				switch(type) {
					case plus.barcode.QR: //扫描成功
						text = 'QR: ';
						break;
					case plus.barcode.EAN13:
						text = 'EAN13: ';
						break;
					case plus.barcode.EAN8:
						text = 'EAN8: ';
						break;
				}
				console.log('二维码电话号码');
				console.log(result.split('?')[1]);
				
				
				plus.runtime.openURL(result.split('?')[1]);
				scan.close();
				mui.openWindow({
					url: "../user/registered.html",
					createNew: true,
					extras: {
						uid: result.split('=')[1]
					}
				})
				
//				mui.openWindow({
//					url: "registered.html",
//					createNew: true,
//					extras: {
//						phone: result
//					}
//				})

			}; // 从相册中选择二维码图片   
			/*function scanPicture() {  
			    plus.gallery.pick(function(path){  
			        plus.barcode.scan(path,onmarked,function(error){  
			            plus.nativeUI.alert( "无法识别此图片" );  
			        });  
			    });  
			}     
			*/
			document.getElementById('back').addEventListener('tap', function() {
				/*mui.openWindow({
					url: 'html/information/information.html',
					id: 'information'
				});*/
				scan.close();
				window.top.location.href = "../../index.html";
			});

			//返回
			mui.back = function() {
				scan.close();
				window.top.location.href = "../../index.html";
			};
		</script>
	</body>

</html>